package cn.iocoder.yudao.module.blog.controller.admin.jiutagclassity;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.blog.controller.admin.jiutagclassity.vo.*;
import cn.iocoder.yudao.module.blog.dal.dataobject.jiutagclassity.BlogJiuTagClassityDO;
import cn.iocoder.yudao.module.blog.convert.jiutagclassity.BlogJiuTagClassityConvert;
import cn.iocoder.yudao.module.blog.service.jiutagclassity.BlogJiuTagClassityService;

@Tag(name = "管理后台 - 案例标签分类")
@RestController
@RequestMapping("/blog/jiu-tag-classity")
@Validated
public class BlogJiuTagClassityController {

    @Resource
    private BlogJiuTagClassityService jiuTagClassityService;

    @PostMapping("/create")
    @Operation(summary = "创建案例标签分类")
    @PreAuthorize("@ss.hasPermission('blog:jiu-tag-classity:create')")
    public CommonResult<Long> createJiuTagClassity(@Valid @RequestBody BlogJiuTagClassityCreateReqVO createReqVO) {
        return success(jiuTagClassityService.createJiuTagClassity(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新案例标签分类")
    @PreAuthorize("@ss.hasPermission('blog:jiu-tag-classity:update')")
    public CommonResult<Boolean> updateJiuTagClassity(@Valid @RequestBody BlogJiuTagClassityUpdateReqVO updateReqVO) {
        jiuTagClassityService.updateJiuTagClassity(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除案例标签分类")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('blog:jiu-tag-classity:delete')")
    public CommonResult<Boolean> deleteJiuTagClassity(@RequestParam("id") Long id) {
        jiuTagClassityService.deleteJiuTagClassity(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得案例标签分类")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('blog:jiu-tag-classity:query')")
    public CommonResult<BlogJiuTagClassityRespVO> getJiuTagClassity(@RequestParam("id") Long id) {
        BlogJiuTagClassityDO jiuTagClassity = jiuTagClassityService.getJiuTagClassity(id);
        return success(BlogJiuTagClassityConvert.INSTANCE.convert(jiuTagClassity));
    }

    @GetMapping("/list")
    @Operation(summary = "获得案例标签分类列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('blog:jiu-tag-classity:query')")
    public CommonResult<List<BlogJiuTagClassityRespVO>> getJiuTagClassityList(@RequestParam("ids") Collection<Long> ids) {
        List<BlogJiuTagClassityDO> list = jiuTagClassityService.getJiuTagClassityList(ids);
        return success(BlogJiuTagClassityConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得案例标签分类分页")
    @PreAuthorize("@ss.hasPermission('blog:jiu-tag-classity:query')")
    public CommonResult<PageResult<BlogJiuTagClassityRespVO>> getJiuTagClassityPage(@Valid BlogJiuTagClassityPageReqVO pageVO) {
        PageResult<BlogJiuTagClassityDO> pageResult = jiuTagClassityService.getJiuTagClassityPage(pageVO);
        return success(BlogJiuTagClassityConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出案例标签分类 Excel")
    @PreAuthorize("@ss.hasPermission('blog:jiu-tag-classity:export')")
    @OperateLog(type = EXPORT)
    public void exportJiuTagClassityExcel(@Valid BlogJiuTagClassityExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<BlogJiuTagClassityDO> list = jiuTagClassityService.getJiuTagClassityList(exportReqVO);
        // 导出 Excel
        List<BlogJiuTagClassityExcelVO> datas = BlogJiuTagClassityConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "案例标签分类.xls", "数据", BlogJiuTagClassityExcelVO.class, datas);
    }

}
